The Commentary plugin in this example does the following:
It returns URLs for commentary
It can verify whether a target screen/attribute has available commentary or not
It retrieves the URL for a target via a simple target-URL Map object
The sample code will cover the following:
Create a Commentary plugin that exclusively returns URL for commentary
Demonstrate how to use the 'target' screen/attribute ID together with the InterviewSession object to verify that URL for the target exists in the mapping object
Demonstrate how to use the 'target' screen/attribute ID together with the InterviewSession object to retrieve the URL
Setup
This sample code needs the following to run:
RedirectCommentary (Commentary plugin)
Parents and Children.zip rulebase
About the RedirectCommentary plugin
This is a demonstration on creating a Commentary plugin that only returns URLs by setting isCommentaryRedirect() to return true all the time
Uses the 'target' screen/attribute ID together with the locale of the interview (from InterviewSession) to check the mapping object if the target exists
Uses the 'target' screen/attribute ID together with the locale of the interview (from InterviewSession) to retrieve the URL for the target in the mapping object
To setup this scenario:
Copy the rulebase .zip file (Parents and Children.zip) from examples\rulebases\compiled to the rulebase folder in Web Determinations (for example, <webroot>\WEB-INF\classes\rulebases)
Copy and install the RedirectCommentary.jar file or the RedirectCommentary.dll file(located in examples\interview-engine\redirect-commentary in either the Java or .NET runtime zip) into Web Determinations; for more information, refer to Create a Plugin.
If you wish to modify the RedirectCommentary code, do the following:
Copy the code for the RedirectCommentary plugin
Modify the static map (variable redirectMap) used for the targets and URL mappings in the code if necessary
Modify the getInstance(arguments) method for registration of the plugin with the rulebase if necessary
Compile and JAR (or build the DLL in .NET) the RedirectCommentary
Run a Web Determinations Interview
How the RedirectCommentary plugin works
Once registered, Web Determinations will call the RedirectCommentary.isCommentaryEnabled() when a screen is to be displayed; the RedirectCommentary plugin always returns true.
When a screen is to be displayed, Web Determinations calls RedirectCommentary.hasCommentary() method for the screen itself, to check if commentary information exists for the screen. The same method is also called for each attribute control to be displayed in the screen. RedirectCommentary.hasCommentary() uses the target information and the locale information from InterviewSession to verify if a URL exists for the target in the mapping object
If RedirectCommentary.hasCommentary() returns true for a target, its label is rendered as a link.
When the user clicks on the label link, Web Determinations calls RedirectCommentary.isCommentaryRedirect() to check if the commentary for the target (the clicked label link) returns URL or HTML content; the RedirectCommentary plugin always returns true.
Web Determinations then calls RedirectCommentary.getCommentaryContent() to get the URL for the target. RedirectCommentary simply retrieves the value from the mapping object using the target String and the locale from the InterviewSession as the key. RedirectCommentary returns the URL value as is, and Web Determinations displays the webpage of the URL as commentary.
To view the source code for the RedirectCommentary sample, refer to examples/interview-engine/redirect-commentary in either the Java or .NET runtime zip file.